package org.compiere.model;

import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Properties;
import java.util.logging.Level;

import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;

public class Mhrmdayschedule extends X_hrm_dayschedule {
	

	/**
	 * 
	 */
	private static final long serialVersionUID = -350494045082727353L;
	
	/**	Static Logger	*/
	private static CLogger	s_log	= CLogger.getCLogger (Mhrmdayschedule.class);

	public Mhrmdayschedule(Properties ctx, int hrm_dayschedule_ID,
			String trxName) {
		super(ctx, hrm_dayschedule_ID, trxName);
	}

	public Mhrmdayschedule(Properties ctx, ResultSet rs, String trxName) {
		super(ctx, rs, trxName);
	}

	public static BigDecimal getHourquota(int hrm_shedulerule_id){
		
		if(hrm_shedulerule_id == 0)
			return null;
		
		BigDecimal result = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		// Employee data from the card
		String sql_ = "SELECT HRM_HOURQUOTA	FROM HRM_DAYSCHEDULE " +
				"WHERE HRM_HOURQUOTA !=0 " +
				"AND AD_CLIENT_ID=? " +
				"AND HRM_DAYSCHEDULE_ID = ? ";
		try
		{
			pstmt = DB.prepareStatement(sql_,null);
			pstmt.setInt(1, Env.getAD_Client_ID(Env.getCtx()));
			pstmt.setInt(2, hrm_shedulerule_id);
			
			rs = pstmt.executeQuery();
			if(rs.next())
				return rs.getBigDecimal(1);			
		}
		catch (SQLException e)
		{
			s_log.log(Level.SEVERE, "product", e);
		}
		finally
		{
			DB.close(rs, pstmt);
			rs = null; pstmt = null;
		}

		return result;
		}
}
